import 'package:flutter/material.dart';
import 'package:flutterdemo/model/post.dart';

class ListViewDemo extends StatelessWidget {
  const ListViewDemo({Key key}) : super(key: key);
  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(8.0),
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              // Image.network(posts[index].imageUrl),
              // 固定图片比例
              AspectRatio(
                aspectRatio: 16 / 9,
                child: Image.network(
                  'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565600849&di=d9f34c8da5d0d53c2c5d8a4867598958&imgtype=jpg&er=1&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fblog%2F201508%2F30%2F20150830095308_UAQEi.thumb.700_0.jpeg',
                  fit: BoxFit.cover,
                ),
              ),
              SizedBox(
                height: 16.0,
              ),
              Text(
                posts[index].title,
              ),
              Text(
                posts[index].author,
              ),
              // 行内多样式的文字
              RichText(
                text: TextSpan(
                    text: 'zhushukun',
                    style: TextStyle(
                      color: Colors.red,
                      fontStyle: FontStyle.italic,
                      fontWeight: FontWeight.w700,
                    ),
                    children: [
                      TextSpan(
                        text: 'xiaoyiyi',
                        style: TextStyle(
                          color: Colors.pink,
                          fontStyle: FontStyle.normal,
                          fontWeight: FontWeight.w100,
                        ),
                      ),
                      TextSpan(
                        text: 'niuruijie',
                        style: TextStyle(
                          color: Colors.black,
                          fontSize: 31.0,
                          fontStyle: FontStyle.italic,
                          fontWeight: FontWeight.w100,
                        ),
                      ),
                    ]),
              ),
              SizedBox(
                height: 16.0,
              ),
            ],
          ),
          //Positioned.fill 表示 完全覆盖 Stack，
          Positioned.fill(
            child: Material(
              color: Colors.transparent,
              // InkWell 水波纹效果
              child: InkWell(
                splashColor: Colors.white.withOpacity(0.3),
                highlightColor: Colors.white.withOpacity(0.1),
                onTap: () {
                  print('object');
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: posts.length,
      itemBuilder: _listItemBuilder,
    );
  }
}
